﻿using System;
using System.Collections.Generic;
using FineUI;
using SDLITS.Common;
using SDLITS.Model;
using System.Data;
using System.Data.SqlClient;

namespace SDLITS.Web.Driver
{
    public partial class CardResetManage : CommonBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnReset_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtMemCardNo.Text))
            {
                Alert.Show("没有要重置的会员卡！");
                return;
            }
            SqlParameter[] sp = new SqlParameter[]{
                    new SqlParameter("@MemCardNo",txtMemCardNo.Text.Trim())
                };
            int result = SDDbSession.Default.FromProc("TableMemCardReset").AddParameter(sp).ExecuteNonQuery();
            if (result > 0)
            {
                txt_addr.Text = "";
                txt_birth.Text = "";
                txt_bs.Text = "";
                txt_cardaddr.Text = "";
                txt_cardname.Text = "";
                txt_cardno.Text = "";
                txt_carno.Text = "";
                txt_cash.Text = "";
                txt_cz.Text = "";
                txt_czdz.Text = "";
                txt_drivername.Text = "";
                txt_end.Text = "";
                txt_fdj.Text = "";
                txt_gcbs.Text = "";
                txt_gchm.Text = "";
                txt_jzdz.Text = "";
                txt_name.Text = "";
                txt_note1.Text = "";
                txt_note2.Text = "";
                txt_phone.Text = "";
                txt_sex.Text = "";
                txt_sfz.Text = "";
                txt_start.Text = "";
                txt_tel.Text = "";
                txtMemCardNo.Text = "";
                Alert.Show("重置会员卡成功！");
            }
        }

        protected void txtMemCardNo_TextChanged(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(txtMemCardNo.Text))
            {
                V_MemCardInfoType card = SDDbSession.Default.From<V_MemCardInfoType>().Where(V_MemCardInfoType._.MemCardNo == txtMemCardNo.Text.Trim()).ToFirst();
                if (card != null)
                {

                    #region 1
                    txt_sfz.Text = card.IDNumber;
                    txt_name.Text = card.Name;
                    txt_addr.Text = card.IDAddress;
                    txt_sex.Text = card.Sex.ToString().ToLower() == "false" ? "女" : "男";
                    txt_birth.Text = card.Birthday.ToString();
                    txt_phone.Text = card.Cell;
                    txt_tel.Text = card.Phone;
                    txt_note1.Text = card.Custom1;
                    txt_note2.Text = card.Custom2;
                    img1.ImageUrl = string.Format("{0}{1}.bmp", @"/Img/IDShot/", card.IDNumber);
                    Image1.ImageUrl = string.Format("{0}{1}.bmp", @"/Img/FingerShot/", card.IDNumber);
                    Image2.ImageUrl = string.Format("{0}{1}.bmp", @"/Img/CamShot/", card.IDNumber);
                    #endregion
                    #region 2
                    txt_start.Text = card.StartDate.ToString();
                    txt_end.Text = card.ExpireDate.ToString();
                    txt_cash.Text = card.LeftCash.ToString();
                    #endregion
                    #region 3
                    txt_drivername.Text = card.DLName;
                    rblsex.SelectedValue = string.IsNullOrEmpty(card.DLSex.ToString()) ? "1" : (Boolean.Parse(card.DLSex.ToString()) ? "1" : "2");
                    txt_cardno.Text = card.DLNumber;
                    txt_cardaddr.Text = card.DLAddress;
                    #endregion
                    #region 4
                    txt_carno.Text = card.CarNo;
                    txt_fdj.Text = card.CarEnginNo;
                    txt_bs.Text = card.CarIDNo;
                    txt_cz.Text = card.CarOwnerName;
                    txt_czdz.Text = card.CarOwnerAddr;
                    txt_gchm.Text = card.GCarNo;
                    txt_gcbs.Text = card.GCarIDNo;
                    #endregion
                }
                else
                {
                    Alert.Show("没有该卡号信息");
                }
            }
        }
    }
}